package leetcode.offer;

/**
 * ClassName: MaxGiftValue
 * Description:leetcode-剑指offer 47.礼物的最大价值
 * date: 2021-11-04 10:13
 *
 * @author liyifan
 */
public class MaxGiftValue {
    public int maxValue(int[][] grid) {
        int row = grid.length;
        int col = grid[0].length;

        for(int i = 0;i < row;i++) {
            for (int j = 0;j < col;j++) {
                if (i == 0 && j == 0)
                    continue;
                if (i == 0) {
                    grid[i][j] += grid[i][j - 1];
                } else if (j == 0) {
                    grid[i][j] +=  grid[i - 1][j];
                } else {
                    grid[i][j] += Math.max(grid[i - 1][j], grid[i][j - 1]);
                }
            }
        }

        return grid[row - 1][col - 1];
    }
}
